package com.cluster.activemq;

import com.cluster.model.Student;
import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.broker.region.TempQueue;
import org.apache.activemq.broker.region.TempTopic;
import org.apache.activemq.broker.region.Topic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by oracle on 2017-06-29.
 */
@Controller
public class ActivemqClusterTest {

    @Autowired
    JmsTemplate jmsMessagingTemplate;

    @RequestMapping("sendMessage")
    @ResponseBody
    public Object sendMessage() {
        jmsMessagingTemplate.convertAndSend("testJms", "this is a test message");
        jmsMessagingTemplate.convertAndSend("testJmsObject", new Student("0001", "黎明"));
        jmsMessagingTemplate.setPubSubDomain(true);
        jmsMessagingTemplate.convertAndSend("topicTest", new Student("0001", "黎明"));
        return "success";
    }

    @JmsListener(destination = "testJms")
    public void testJms(String message) {
        System.out.println("message = " + message);
    }

    @JmsListener(destination = "testJmsObject")
    public void testJmsObject(Student student) {
        System.out.println("student = " + student);
    }

    @JmsListener(destination = "topicTest", containerFactory = "topicFactory")
    public void topicTest1(Student student) {
        System.out.println("topic1 student = " + student);
    }

//    @JmsListener(destination = "topicTest", containerFactory = "topicFactory")
    public void topicTest2(Student student) {
        System.out.println("topic2 student = " + student);
    }
}
